package com.yn.xgame.logic.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.apache.commons.codec.binary.Hex;

public class MD5Utils {

	private MD5Utils() {
		
	}
	
	public static byte[] encrypt(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException{
		MessageDigest mdInst=MessageDigest.getInstance("MD5");
		mdInst.update(input.getBytes("utf-8"));
		return mdInst.digest();
	}
	
	public static String encryptTohex(String input) {
		try {
			return Hex.encodeHexString(encrypt(input));
		} catch (Exception e) {
			throw new RuntimeException(e);
		} 
	}
	
	public static void main(String[] args) {
		String input="1";
		String encrypted=encryptTohex(input);
		System.out.println(encrypted);
	}
}
